home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
SGI Hot Mix 17
/
Hot Mix 17.iso
/
HM17_SGI
/
research
/
examples
/
demo
/
demosrc
/
sets__define.pro
< prev
next >
Wrap
Text File
|
1997-07-08
|
6KB
|
162 lines
;-----------------------------------------------------------------------------
; This is the Definition File for the SETS class. This file includes the
; following set methods:
; Init - Initialize a SETS object
; CleanUp - Clean up a SETS object.
; GetProperty - Obtain property information for a given SETS object.
;
;*****************************************************************************
; Sets::Init: Initialize an instance of the 'sets' class.
; Inputs: name, [data, op, set1Name, set2Name, set1Size, set2Size]
; Outputs: 1B - success or 0B - failure.
; Side Effects: On success an instance of the 'sets' class is created.
;
;*****************************************************************************
function Sets::Init , name, data, $
OP = op, SET1_NAME =set1Name, SET2_NAME = set2Name, $
SET1_SIZE = set1Size, SET2_SIZE = set2Size
FORWARD_FUNCTION TypeOf
; Check to see that the name argument is passed in.
;
if N_PARAMS() lt 1 then begin
return, 0b
endif
self.name = name
; If this new object is the result of a set operation then
; define data for the operation, and the 'parent' objects.
;
if N_ELEMENTS(op) gt 0 then begin
self.op = op
if N_ELEMENTS(set1Name) gt 0 then $
self.set1Name = set1Name
if N_ELEMENTS(set2Name) gt 0 then $
self.set2Name = set2Name
if N_ELEMENTS(set1Size) gt 0 then $
self.set1Size = set1Size
if N_ELEMENTS(set2Size) gt 0 then $
self.set2Size = set2Size
;**** Error would occur if set1Name or set2Name are undefined!!!!!
opDesc = 'This is the ' + STRLOWCASE(op) + ' of set ' $
+ set1Name + ' and set ' + set2Name + '. '
endif else $
opDesc = ''
; If the object has data then initialize the appropriate instance data.
;
if ((N_PARAMS() eq 2) and (N_ELEMENTS(data) gt 0))then begin
self.type = TypeOf(data)
uniqData = data[UNIQ(data, SORT(data))]
self.pData = PTR_NEW(uniqData)
self.size = N_ELEMENTS(uniqData)
; Create the object's description data
;
elementDesc = 'This set contains ' + STRTRIM(STRING(self.size),2) + $
' unique ' +self.type
if self.size gt 1 then $
elementDesc = elementDesc + 's. ' $
else $
elementDesc = elementDesc + '. '
minDesc = 'The minimum is ' + STRTRIM(STRING(MIN(uniqData)),2) + ' and '
maxDesc = 'the maximum is ' + STRTRIM(STRING(MAX(uniqData)),2) + '.'
mainDesc = 'Set ' + name + ': ' + opDesc + elementDesc + minDesc + maxDesc
endif else begin ; Empty Set object
self.size = 0
mainDesc = 'Set '+ name + ': ' + opDesc + 'The result is the Empty Set.'
endelse
self.pDesc = PTR_NEW([mainDesc]) ; Create a pointer to the description data
return, 1b
end
;*****************************************************************************
; Sets::GetProperty: Pass instance data to the caller
; Inputs: NONE
; Outputs: [data, desc, name, op, size, set1Name, set2Name,
; set1Size, set2Size, type]
; Side Effects: NONE
;
;*****************************************************************************
pro Sets::GetProperty, DATA = data, $
DESC = desc, NAME = name, OP = op, SIZE = size, $
SET1_NAME = set1Name, SET2_NAME = set2Name, $
SET1_SIZE = set1Size, SET2_SIZE = set2Size, TYPE = type
; Check to see which properties are requested and return them to
; the caller
;
if (ARG_PRESENT(size) or ARG_PRESENT(data)) then begin
size = self.size
if size ne 0 then $ ; Contains data?
data = *self.pData
endif
if ARG_PRESENT(desc) then $
desc = *self.pDesc
if ARG_PRESENT(name) then $
name = self.name
if ARG_PRESENT(op) then $
op = self.op
if ARG_PRESENT(set1Name) then $
set1Name = self.set1Name
if ARG_PRESENT(set2Name) then $
set2Name = self.set2Name
if ARG_PRESENT(set1Size) then $
set1Size = self.set1Size
if ARG_PRESENT(set2Size) then $
set2Size = self.set2Size
if ARG_PRESENT(type) then $
type = self.type
end
;*****************************************************************************
; Sets::CleanUp: Free any pointers used by the object
; Inputs: NONE
; Outputs: NONE
; Side Effects: Frees self.pData and self.pDesc
;
;*****************************************************************************
pro Sets::CleanUp
; Free data and description pointers if it is valid
;
if PTR_VALID(self.pData) then $
PTR_FREE, self.pData
if PTR_VALID(self.pDesc) then $
PTR_FREE, self.pDesc
end
;*****************************************************************************
; Sets__Define: Define the class structure for the 'sets' class
; Inputs: NONE
; Outputs: NONE
; Side Effects: Creates definition of 'sets' structure in heap
;
;*****************************************************************************
pro Sets__Define
junk = { sets , $
pData:PTR_NEW() , $ ; the contents of the set
pDesc: PTR_NEW() , $ ; description of set
name: '' , $ ; one letter name
op: '', $ ; the set operation which produced this set
set1Name: '', $ ; Name of 'parent' set 1
set2Name: '', $ ; Name of 'parent' set 1
set1Size: 0L, $ ; # of elements in 'parent' set 1
set2Size: 0L, $ ; # of elements in 'parent' set 2
size: 0L , $ ; # of unique elements
type:'' $ ; datatype
}
end